package com.rp.configure.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rp.common.result.ResultDTO;
import com.rp.common.utils.NullIs;
import com.rp.configure.entity.Alarm;
import com.rp.configure.entity.AlarmAll;
import com.rp.configure.service.AlarmAllService;
import com.rp.configure.service.AlarmService;
import com.rp.system.user.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author vicente
 * @since 2021-07-18
 */
@RestController
@RequestMapping("/alarm-all")
@Api("全局报警处理")
public class AlarmAllController {
    @Autowired
    AlarmAllService alarmAllService;
    @PostMapping("/insert")
    public ResultDTO insert(@RequestBody AlarmAll alarmAll) {


        return ResultDTO.tf(alarmAllService.save(alarmAll));
    }
    @PutMapping("/update")
    @ApiOperation(value = "修改全局")
//    @RequiresRoles(value={"admin","vip"},logical = Logical.OR)
    public ResultDTO update(@RequestBody AlarmAll alarmAll) {

        return ResultDTO.tf(alarmAllService.updateById(alarmAll));
    }
    @GetMapping("/list")
    @ApiOperation(value = "根据项目id查询")
    public ResultDTO<List<Alarm>> list(@RequestParam(value = "subjectId") String subjectId) {
        List<Alarm> list=alarmAllService.listBySubject(subjectId);
        return ResultDTO.success().data(list);
    }
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除")
//    @RequiresRoles(value={"admin","vip"},logical = Logical.OR)
    public ResultDTO delete(@RequestBody @ApiParam(value = "id", required = true) String id) {
        return ResultDTO.tf(alarmAllService.removeById(id));
    }
    @DeleteMapping("/deleteAll")
    @ApiOperation(value = "批量删除")
//    @RequiresRoles(value={"admin","vip"},logical = Logical.OR)
    public ResultDTO deleteAll(@RequestBody @ApiParam(value = "id(英文逗号隔开)", required = true) String ids) {
        return ResultDTO.tf(alarmAllService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
